﻿import $ = require("jquery");
import ko = require("knockout");

class Hold {
    public static create() {
        ko.bindingHandlers.Hold = {
            init: (element, valueAccessor: () => KnockoutObservable<number>|any) => {
                var callback = valueAccessor();
                $(element).on("manip_hold", (event, args: { clientX: number; clientY: number }) => {
                    var r = element.getBoundingClientRect();
                    var x = args.clientX - r.left;
                    var y = args.clientY - r.top;
                    callback({x: x, y: y});
                });
            },
            update: () => { }
        }
    }
}

export = Hold;